﻿using System;

namespace Lilium.LParse
{
    public static class ParserExtensions
    {
        public static TResult Parse<TResult>(this Parser<char, TResult> parser, string value)
        {
            if (parser == null) throw new ArgumentNullException("parser");

            var state = new StringParserState(value);
            var result = parser(state);

            if (state.Failed)
                throw state.GetParserException();

            return result;
        }
    }
}